home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / others / pcal / pcal.c < prev    next >
Text File  |  1992-02-21  |  46KB  |  1,561 lines

  1. static char  VERSION_STRING[]    = "@(#)pcal v4.3 - generate Postscript calendars";
  2. /*
  3.  * pcal.c - generate PostScript file to print calendar for any month and year
  4.  *
  5.  * The original PostScript code to generate the calendars was written by
  6.  * Patrick Wood (Copyright (c) 1987 by Patrick Wood of Pipeline Associates,
  7.  * Inc.), and authorized for modification and redistribution.  The calendar
  8.  * file inclusion code was originally written in "bs(1)" by Bill Vogel of
  9.  * AT&T.  Patrick's original PostScript was modified and enhanced several
  10.  * times by King Ables, Tom Tessin, and others whose names have regrettably 
  11.  * been lost.  This C version was originally created by Ken Keirnan of Pacific
  12.  * Bell; additional enhancements by Joseph P. Larson, Ed Hand, Andrew Rogers, 
  13.  * Mark Kantrowitz, Joe Brownlee, Andy Fyfe, and Geoff Kuenning.  The moon
  14.  * routines were originally written by Jef Poskanzer and Craig Leres, and
  15.  * were incorporated into Pcal by Richard Dyson.
  16.  *
  17.  * Contents:
  18.  *
  19.  *        alt_fopen
  20.  *        check_numargs
  21.  *        color_msg
  22.  *        gen_shading
  23.  *        get_args
  24.  *        get_flag
  25.  *        init_misc
  26.  *        main
  27.  *        set_color
  28.  *        set_debug_flag
  29.  *        usage
  30.  *
  31.  * Revision history:
  32.  *
  33.  *    4.3    AWR    12/06/91    Attempted to simplify some of the
  34.  *                    mysteries surrounding command-line
  35.  *                    parsing; moved some processing from
  36.  *                    get_args() to new check_numargs()
  37.  *
  38.  *            12/05/91    Search for moon file in directory
  39.  *                    where Pcal lives (cf. moonphas.c)
  40.  *
  41.  *            12/03/91    Add -s flag to override default values
  42.  *                    for date/fill box shading
  43.  *
  44.  *            11/22/91    Use cvt_escape() (new; cf. pcalutil.c)
  45.  *                    to convert escape sequences in command
  46.  *                    line strings
  47.  *
  48.  *            11/18/91    Improve documentation; add init_misc()
  49.  *                    as catch-all for various initializations
  50.  *
  51.  *            10/25/91    Support moon phases as wildcards
  52.  *
  53.  *            10/17/91    Add -Z flag to generate debugging
  54.  *                    information; add a pre-pass through
  55.  *                    command line flags to detect -ZO
  56.  *                    prior to parsing PCAL_OPTS
  57.  *
  58.  *            10/15/91    Revise logic of date file search
  59.  *
  60.  *    4.2    AWR    10/08/91    Add -k and -K flags to control
  61.  *                    positioning of small calendars
  62.  *
  63.  *            10/03/91    Add "note{/<n>}" to select box for
  64.  *                    note text (as per Geoff Kuenning)
  65.  *
  66.  *                    Add -S flag to suppress generation
  67.  *                    of the small calendars
  68.  *
  69.  *            10/02/91    Add -N flag to specify alternate
  70.  *                    heading for notes box
  71.  *
  72.  *                    Allow user to specify alternate notes
  73.  *                    font size (-n <name>/<size>)
  74.  *
  75.  *            10/01/91    Add -u flag to generate version info
  76.  *                    and parameter usage message
  77.  *
  78.  *            09/30/91    Support "if" and "elif" in date file
  79.  *
  80.  *            09/19/91    Add -c flag to generate input file for
  81.  *                    Un*x "calendar" utility
  82.  *
  83.  *    4.11    AWR    08/20/91    Add support for "nearest" keyword
  84.  *                    (as per Andy Fyfe)
  85.  *
  86.  *                    define "whole_year" when -w set
  87.  *
  88.  *        AWR    08/21/91    Support %u, %w, %D, %M format specs
  89.  *                    and optional number following %[+-]
  90.  *                    (cf. writefil.c)
  91.  *
  92.  *    4.1    AWR    08/16/91    Add -G flag to print "gray" dates as
  93.  *                    outlined, gray-filled characters
  94.  *
  95.  *                    Fix potential bug in julday() (cf.
  96.  *                    moonphas.c)
  97.  *
  98.  *    4.02    AWR    07/02/91    Add -v flag to print version info only;
  99.  *                    call find_executable() to get true
  100.  *                    program pathname (cf. pcalutil.c);
  101.  *                    add format specifiers to text strings
  102.  *                    (cf. writefil.c)
  103.  *
  104.  *    4.01    AWR    03/19/91    Incorporate revised moonphas.c (q.v.)
  105.  *
  106.  *    4.0    AWR    02/24/91    Add alt_fopen() to search for file
  107.  *                    in alternate path; use to look for
  108.  *                    date file in same directory as
  109.  *                    Pcal executable (as per Floyd Miller)
  110.  *
  111.  *                    Support negative ordinals (cf.
  112.  *                    readfile.c, pcalutil.c)
  113.  *
  114.  *                    Support expressions in preprocessor
  115.  *                    "if{n}def" lines (cf. exprpars.c)
  116.  *
  117.  *                    Support "even", "odd" ordinals (cf.
  118.  *                    readfile.c) and ordinals > 5th
  119.  *
  120.  *                    Support -B (leave unused boxes blank)
  121.  *                    flag
  122.  *
  123.  *                    Separated into moonphas.c, pcal.c,
  124.  *                    pcalutil.c, readfile.c, and writefil.c;
  125.  *                    added support for moon phase file
  126.  *
  127.  *                    Support -w (whole year) flag; fix
  128.  *                    various bugs and nonportable constructs
  129.  *
  130.  *    3.0    AWR    12/10/90    Support concept of "weekday", "workday",
  131.  *                    and "holiday" (and converses)
  132.  *
  133.  *                    Substantial revision of program logic:
  134.  *                    extracted pcaldefs.h and pcallang.h,
  135.  *                    moving all language dependencies (even
  136.  *                    flag names) to the latter.
  137.  *
  138.  *                    add -I flag to reinitialize all
  139.  *                     flags to program defaults; -j and -J
  140.  *                    flags (print Julian dates); add -x,
  141.  *                     -y, -X, -Y flags (as per Ed Hand)
  142.  *                    for output scaling and translation
  143.  *
  144.  *                    allow "wildcard" dates (e.g., "all
  145.  *                    Thursday{s} in Oct", "last Friday in
  146.  *                    all") and notes ("note all <text>);
  147.  *                    print full "help" message (including
  148.  *                    date file syntax)
  149.  *
  150.  *    2.6    AWR    10/15/90    parse floating dates (e.g. "first
  151.  *                    Monday in September") and relative
  152.  *                    floating dates (e.g., "Friday after
  153.  *                    fourth Thursday in November"); simplify
  154.  *                    logic of -F option; add -F to usage 
  155.  *                    message; replace COLOR_MSG() string
  156.  *                    with color_msg() routine; add -h
  157.  *                    (help message) and -A | -E (American |
  158.  *                    European date format) flags; renamed
  159.  *                    flag sets for clarity; more comments
  160.  *
  161.  *    2.5    JAB    10/04/90    added -F option
  162.  *
  163.  *    2.4    ---    10/01/90    * no modifications *
  164.  *
  165.  *    2.3    JWZ/AWR    09/18/90    added moon routines
  166.  *
  167.  *    2.2    AWR    09/17/90    revise logic of parse(); new usage
  168.  *                    message
  169.  *
  170.  *        JAB/AWR    09/14/90    support "note" lines in date file
  171.  *
  172.  *    2.1    MK/AWR    08/27/90    support -L, -C, -R, -n options;
  173.  *                    print holiday text next to date
  174.  *
  175.  *        AWR    08/24/90    incorporate cpp-like functionality;
  176.  *                    add -D and -U options; save date file
  177.  *                    information in internal data structure;
  178.  *                    look for PCAL_OPTS and PCAL_DIR; look
  179.  *                    for ~/.calendar and ~/calendar
  180.  *
  181.  *    2.0    AWR    08/08/90    included revision history; replaced -r
  182.  *                    flag with -l and -p; replaced -s and -S
  183.  *                    flags with -b and -g; recognize flags
  184.  *                    set in date file; translate ( and ) in
  185.  *                    text to octal escape sequence; usage()
  186.  *                    message condensed to fit 24x80 screen
  187.  *
  188.  *    Parameters:
  189.  *
  190.  *        pcal [opts]        generate calendar for current month/year
  191.  *                    (current year if -w flag specified)
  192.  *
  193.  *        pcal [opts] yy        generate calendar for entire year yy
  194.  *
  195.  *        pcal [opts] mm yy    generate calendar for month mm
  196.  *                    (Jan = 1), year yy (19yy if yy < 100)
  197.  *                    (12 months starting with mm/yy if -w
  198.  *                    specified)
  199.  *
  200.  *        pcal [opts] mm yy n    as above, for n consecutive months (n
  201.  *                    rounded to next multiple of 12 if -w
  202.  *                    specified)
  203.  *
  204.  *    Output:
  205.  *
  206.  *        PostScript file to print calendars for all selected months.
  207.  *
  208.  *    Options:
  209.  *
  210.  *        -I        initialize all parameters to program defaults
  211.  *
  212.  *        -b <DAY>    print specified weekday in black
  213.  *        -g <DAY>    print specified weekday in gray
  214.  *                (default: print Saturdays and Sundays in gray)
  215.  *
  216.  *        -G        print "gray" dates as filled outlines
  217.  *        -O        print "gray" dates as unfilled outlines
  218.  *                (default: gray characters)
  219.  *
  220.  *        -s {<DATE>}{/<FILL>}
  221.  *                specify alternate shading values for dates
  222.  *                and fill boxes
  223.  *                (default: dates = 0.8, fill boxes = 0.9)
  224.  *
  225.  *        -d <FONT>    specify alternate font for day names
  226.  *                (default: Times-Bold)
  227.  *
  228.  *        -n <FONT>{/<SIZE>}
  229.  *                specify alternate font/size for notes in boxes
  230.  *                (default: Helvetica-Narrow/6)
  231.  *
  232.  *        -t <FONT>    specify alternate font for titles
  233.  *                (default: Times-Bold)
  234.  *
  235.  *        -D <SYM>    define preprocessor symbol
  236.  *        -U <SYM>    un-define preprocessor symbol
  237.  *
  238.  *        -e        generate empty calendar (ignore date file)
  239.  *
  240.  *        -f <FILE>    specify alternate date file (default:
  241.  *                ~/.calendar on Un*x, SYS$LOGIN:CALENDAR.DAT
  242.  *                on VMS, s:calendar.dat on Amiga; if
  243.  *                environment variable [logical name on VMS]
  244.  *                PCAL_DIR exists, looks there instead; if
  245.  *                not found in either place, looks in same
  246.  *                directory as Pcal executable)
  247.  *
  248.  *        -o <FILE>    specify alternate output file (default:
  249.  *                stdout on Un*x, CALENDAR.PS on VMS, 
  250.  *                RAM:calendar.ps on Amiga)
  251.  *
  252.  *        -L <STRING>    specify left foot string   (default: "")
  253.  *        -C <STRING>    specify center foot string (default: "")
  254.  *        -R <STRING>    specify right foot string  (default: "